const qs = require('qs');
const complie = require('../eason/complie');
const { scriptReg, styleReg, removeTagReg, htmlReg } = require('./Utils');

module.exports = function selectLoader(source) {
  const { resourceQuery } = this;

  const query = qs.parse(resourceQuery.slice(1));
  
  if(query.type === 'style') {
    const styleCode = styleReg.exec(source)[0];
    return removeTagReg.exec(styleCode)[0];
  }

  if(query.type === 'script') {
    const scriptCode = scriptReg.exec(source)[0];
    return removeTagReg.exec(scriptCode)[0];
  }

  if(query.type === 'html') {
    const htmlCode = htmlReg.exec(source)[0];
    return complie(htmlCode);
  }
}